/*
 * Class: Friend Manager
 * author: Zaki Ullah
 * Company: Gaminations Inc.
*/
exports.MMFriendManager = Core.Class.singleton({
	
	classname: 'MMFriendManager',
	
	initialize: function()
	{
		this._friends = [];
		this._friendsDictionary = null;
		
		this._friendsDictionary = new GAMutableDictionary();
	},
	
	
	getFriendsFromMobage: function(callback)
	{
		//TODO GET FRIENDS WITH GAME 
		//Social.Common.People.getFriends()
		Social.Common.People.getFriendsWithGame(GAConfigurations.getRecordID(), ['displayName','id'], null,  function(error, friends, newResult)
		{
			if(error)
			{
				UIFactory.hideProgressHUD();
				var alertBox = UIFactory.getAlertBox(Core.Localization.getString("ERROR"), Core.Localization.getString("UNABLE_TO_LOAD_FRIENDS"), ["Retry"], this, this.retryGettingFriends.bind(this));
			}
			else
			{
//				this._friends = friends;
				MMFriendManager.populateFriendsDictionary(callback, friends);
			}
		}.bind(this));
	},
	
	populateFriendsDictionary: function(callback, friends)
	{
		var dummyFriend = TCUtil.getDummyFriendObject();
		this._friendsDictionary.setObject("999",dummyFriend);
		var noOfFriends = friends.length;
		
		var key = null;
		var value = null;
		for(var i = 0; i < noOfFriends; i++)
		{
			key = friends[i].id;
			value = friends[i];
			this._friendsDictionary.setObject(key, value);
		}
		//remove spinner here 
		callback(this._friendsDictionary);
		
		UIFactory.hideProgressHUD();
	},
	
	getFriendsDictionary: function(callback)
	{
		this._callback = callback;
		//show Spinner here 
		UIFactory.showProgressHUD(Core.Localization.getString("GETTING_MOBAGE_FRIENDS"));	
		MMFriendManager.getFriendsFromMobage(callback);
	},
	
	retryGettingFriends: function()
	{
		if(!TutorialManager.getHasCompletedTutorial())
		{
			UIFactory.showProgressHUD(Core.Localization.getString("GETTING_MOBAGE_FRIENDS"));
			MMFriendManager.getFriendsFromMobage(this._callback);
		}
	},
	
	getVisitingFriendObj: function()
	{
		return this._friendObj;
	},
	
	setVisitingFriendObj: function(friendObj)
	{
		this._friendObj = friendObj;
	},
	
	destroy: function()
	{
		
	}

});